package cn.xiaosiyuan.util.file;

import cn.hutool.core.io.file.FileWriter;
import cn.hutool.core.util.CharsetUtil;
import cn.xiaosiyuan.util.interfaces.IFileUtil;

import java.io.File;

public class FileUtil implements IFileUtil {


    private String path;

    private File file = null;

    public void setPath(String path) {
        this.path = path;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public String getPath() {
        return path;
    }

    public File getFile() {
        return file;
    }

    @Override
    public IFileUtil createFile(String path) {
        file = (cn.hutool.core.io.FileUtil.exist(path)) ? new File(path) : cn.hutool.core.io.FileUtil.newFile(path);
        return this;
    }

    @Override
    public boolean append(String content) {
        File file = this.getFile();
        FileWriter fileWriter = FileWriter.create(file, CharsetUtil.CHARSET_UTF_8);
        fileWriter.append(content);
        return true;
    }

    @Override
    public boolean write(String content) {
        File file = this.getFile();
        FileWriter fileWriter = FileWriter.create(file, CharsetUtil.CHARSET_UTF_8);
        fileWriter.write(content);
        return true;
    }


}
